package com.ruoyi.youtian.controller;

import java.util.List;
import com.ruoyi.youtian.domain.vo.TEarlyWarningRecordVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.youtian.domain.TEarlyWarningRecord;
import com.ruoyi.youtian.service.ITEarlyWarningRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 触发预警记录Controller
 * 
 * @author ruoyi
 * @date 2022-10-12
 */
@Controller
@RequestMapping("/earlyWarningRecord")
public class TEarlyWarningRecordController extends BaseController
{
    private String prefix = "earlyWarningRecord/earlyWarningRecord";

    @Autowired
    private ITEarlyWarningRecordService tEarlyWarningRecordService;

    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:view")
    @GetMapping()
    public String earlyWarningRecord()
    {
        return prefix + "/earlyWarningRecord";
    }


    /**
     * 查询触发预警报警记录列表
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:list")
    @PostMapping("/list2")
    @ResponseBody
    public TableDataInfo list2(TEarlyWarningRecordVo tEarlyWarningRecordVo)
    {
        startPage();
        List<TEarlyWarningRecordVo> list = tEarlyWarningRecordService.selectTEarlyWarningRecordVoList(tEarlyWarningRecordVo);
        return getDataTable(list);
    }

    /**
     * 导出触发预警记录列表
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:export")
    @Log(title = "触发预警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TEarlyWarningRecord tEarlyWarningRecord)
    {
        List<TEarlyWarningRecord> list = tEarlyWarningRecordService.selectTEarlyWarningRecordList(tEarlyWarningRecord);
        ExcelUtil<TEarlyWarningRecord> util = new ExcelUtil<TEarlyWarningRecord>(TEarlyWarningRecord.class);
        return util.exportExcel(list, "触发预警记录数据");
    }

    /**
     * 新增触发预警记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存触发预警记录
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:add")
    @Log(title = "触发预警记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TEarlyWarningRecord tEarlyWarningRecord)
    {
        return toAjax(tEarlyWarningRecordService.insertTEarlyWarningRecord(tEarlyWarningRecord));
    }

    /**
     * 修改触发预警记录
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TEarlyWarningRecord tEarlyWarningRecord = tEarlyWarningRecordService.selectTEarlyWarningRecordById(id);
        mmap.put("tEarlyWarningRecord", tEarlyWarningRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存触发预警记录
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:edit")
    @Log(title = "触发预警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TEarlyWarningRecord tEarlyWarningRecord)
    {
        return toAjax(tEarlyWarningRecordService.updateTEarlyWarningRecord(tEarlyWarningRecord));
    }

    /**
     * 删除触发预警记录
     */
    @RequiresPermissions("earlyWarningRecord:earlyWarningRecord:remove")
    @Log(title = "触发预警记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tEarlyWarningRecordService.deleteTEarlyWarningRecordByIds(ids));
    }
}
